<?php
namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset="UTF-8"');
class OrderController extends CommonController {
    public function index(){
        $db=M('order');
        $uid=$_SESSION['uid'];
        $data=$db->where("uid={$uid}")->select();
        $timeArray = array( );
        foreach ($data as $key => $value) {

            if (!in_array($value['time'], $timeArray)) {
               array_push($timeArray,$value['time'] );
            }
        }
    	foreach ($timeArray as $key => $time) {
            $where = array(
                        'time' => $time, 
                        'status' => '已付款',
                        );
            $data=$db->where($where)->select();
            foreach ($data as $k => $val) {
               $val['property']=json_decode($val['property'],true);
               $data[$k]['property']=$val['property'];
            }
            $orderArray[$key]['time']=$time;
            $orderArray[$key]['data']=$data;
            $orderArray[$key]['status']=$data[0]['status']; 
            $orderArray[$key]['delivery']=$data[0]['delivery'];            
        }
        rsort($orderArray);
        foreach ($orderArray as $key => $value) {
            if(empty($value['data'])){
                unset($orderArray[$key]);
            }
        }
        $this->assign('orderArray',$orderArray);

        $dc=M('shopcart');//统计购物车的数量
        $uid=$_SESSION['uid'];
        if (!empty($uid)) {
            $dataCount=$dc->where("uid={$uid}")->select();
            $count=count($dataCount);
            $this->assign('count',$count);  
        }   
       
        $this->display();
    }
   
}